// pages/userinfo/userinfo.js
var app = getApp()

var userInfo = null;
Page({

  /**
   * 页面的初始数据
   */
  globalData: {
    appid: 'wxd58721792e664036',//appid需自己提供，此处的appid我随机编写
    secret: '29e81fa7f8ee0e7b1e5f1916832ceabf',//secret需自己提供，此处的secret我随机编写
  },
  data: {
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),

    disabled: true,
    btnstate: "default",
    account: "",
    password: ""
  },

  pwdBlur: function (e) {
    var password = e.detail.value;
    if (password != '') {
      this.setData({ password: password });
    }

    if (password != '') {
      this.setData({ disabled: false, btnstate: "primary", account: password });
    } else {
      this.setData({ disabled: true, btnstate: "default" });
    }
  },

  formSubmit: function (e) {
    console.log(e.detail.value.num)
    console.log(e.detail.value.pwd)
    var that = this;
    var num = e.detail.value.num;
    var pwd = e.detail.value.pwd;
    var openid = wx.getStorageSync('openid');
    console.log(openid)
    if (num.length < 5 || pwd.length < 6) {
      wx.showToast({
        title: '用户名长度小于5，或密码长度小于6',
        duration: 2000
      })
    } else {
      wx.request({
        method: "GET",
        url: "http://localhost:8080/WEBPRO_18/xcx_adminAdd",
        data: {
          'num': num,
          'pwd': pwd,
          'openid': openid,
        },
        header: {
          'content-type': 'application/json'
        },

        success: function (res) {
          console.log(res.data.code)
          if (res.data.code == 200) {
            wx.showToast({
              title: '成功绑定',//'保存成功',
              duration: 2000
            })
            // getApp().globalData.showDialog = '1'
            wx.switchTab({
              url: '/pages/wd/wd',
            })
          }
          else {
            title: '绑定失败'
            duration: 2000
          }

        }
      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  getUserInfo: function (e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})